/*******************************************************************************
 * Copyright (c) 2010 Mikhail Garber.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License (LGPL)
 * which accompanies this distribution
 * 
 * Contributors:
 *     Mikhail Garber - initial API and implementation
 ******************************************************************************/
package plumber.model;

import org.slf4j.LoggerFactory;

/**
 * an Outcome that matches particular class being returned from Step execution
 * (classname of the return value)
 * @author mgarber
 *
 */
@SuppressWarnings("serial")
public class ClassBasedOutcome extends StepOutcome {

	private Class<?> triggerClass;

	public Class<?> getTriggerClass() {
		return triggerClass;
	}

	/**
	 * set class that will cause this Outcome to match
	 * @param triggerClass
	 */
	public void setTriggerClass(Class<?> triggerClass) {
		this.triggerClass = triggerClass;
	}

	/* (non-Javadoc)
	 * @see plumber.model.StepOutcome#validateImpl()
	 */
	@Override
	public void validateImpl() {
		if(triggerClass == null) {
			throw new IllegalStateException("trigger class is missing");
		}
	}

	/**
	 * match if class of the value matches the triggering class
	 * @see plumber.model.StepOutcome#match(java.lang.Object)
	 */
	@Override
	public boolean match(Object val) {
		LoggerFactory.getLogger(this.getClass()).info("comparing val:" + val + " with " + triggerClass);
		return (val != null) && (val.getClass().equals(triggerClass));
	}
	
	
	
}
